class Solution:
    def lengthOfLongestSubstring(self, s):
        result = 0
        subString = []

        for ch in s:
            if ch not in subString:
                subString.append(ch)
            else:
                result = result if result > len(subString) else len(subString)
                print(len(subString), subString)
                subString = []
                subString.append(ch)

        return  result if result > len(subString) else len(subString)



if __name__ == '__main__':
    sl = Solution()
    result = sl.lengthOfLongestSubstring("dvdf")
    print(result)






import random

class Solution:
    def lengthOfLongestSubstring(self, s):
        result = 0
        subString = []

        for ch in s:
            if ch not in subString:
                subString.append(ch)
            else:
                result = result if result > len(subString) else len(subString)
                # print(len(subString), subString)

                print(subString)
                for i in range(len(subString)):
                    if subString[i] == ch:
                        subString = subString[i+1:]     # cannot give "" directly, can only remove the same letter and before
                        break
                print("After remove the same char, list is ", subString, "len is :", len(subString), "\n")
                subString.append(ch)

        return  result if result > len(subString) else len(subString)



if __name__ == '__main__':
    # fullstring = random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')
    # fullstring = ''.join(random.sample(
    #     ['z', 'y', 'x', 'w', 'v', 'u', 't', 's', 'r', 'q', 'p', 'o', 'n', 'm', 'l', 'k', 'j', 'i', 'h', 'g', 'f', 'e',
    #      'd', 'c', 'b', 'a'], 20))
    fullstring = ''.join(random.sample(['z', 'y', 'x', 'w', 'v', 'u'], 5))
    print(fullstring)

    sl = Solution()
    result = sl.lengthOfLongestSubstring("zyxwxwxyvvs")
    print(result)

